package 课程设计报告_hb_7_5;

import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.junit.Test;

/**
 * @author Jiang Zhiyan
 *
 * 2021年7月5日 下午3:31:02
 *
 */
public class CopyPicture {
	
	@Test
	public void testCopy() {
		  copyFile01("./demo/a.jpg","./demo/b.jpg");
	}
	
	public void copyFile01(String srcFile, String distFile) {
		try(FileInputStream fis = new FileInputStream(srcFile);
				 FileOutputStream fos = new FileOutputStream (distFile);){
//			定义一个缓存的byte数组
			byte [] buff = new byte[1024];
			int count =-1;
			while( (count = fis.read(buff)) != -1) {
				fos.write(buff,0, count);
			}
			fos.flush();
	  }  catch(Exception e ){
		  throw new RuntimeException(e);
	  }
	
	}
//	文件的赋值
	@Test
	public void copyFile(String srcFile,String distFile){
		try(FileInputStream fis = new FileInputStream(srcFile);
			FileOutputStream fos= new FileOutputStream(distFile);){
           int data = -1;
           while((data = fis.read()) != -1) {
        	   fos.write(data);
           }
           fos.flush();
		}catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}
